<%@page import="fr.vahren.sriksal.controller.bean.UserInfo"%>


<h1>Welcome <em><%if(session.getAttribute("user") != null){ out.print(((UserInfo)session.getAttribute("user")).getLogin());}else{ out.print("WHO ARE YOU??");} %></em></h1>

<p><a href="game/createMap">Create a new MAP</a></p>

<p><a href="joinMap.jsp">Join an existing MAP</a></p>

<p>You are part of these MAPS:
</p>

<table id="mapList">

</table>

<script type="text/javascript">

window.addEventListener('load', eventWindowLoaded, false);
function eventWindowLoaded() {
   getMapList();
}

function getMapList(){
	requestJSON('game/retrieveMapList',function(res){
		var mapList = JSON.parse(res).maps;
		fillList(mapList);
	});
}

function fillList(mapList){
	var table = '';
	for(var id in mapList){
		table += '<tr><td>Map id='+mapList[id][0]+'</td><td>User id='+mapList[id][1]+'</td><td><button onclick="javascript:showMap('+mapList[id][0]+')">SHOW</button></td></tr>';
	}
	console.log(table);
	setText('mapList',table);
}

function showMap(id){
	window.location.href = "game/showMapFromList?mapId="+id;
}

</script>